package org.example2;

import java.util.concurrent.TimeUnit;

public class ThreadStateTest1 {

    /**
     * 可以看到当线程1,调用锁.wait方法后,线程状态变为waiting
     */
    public static void main(String[] args) throws Exception{

        Object lock = new Object();

        Thread thread = new Thread(() -> {
            synchronized (lock) {
                try {
                    System.out.println("进入lambda的synchronized了");
                    lock.wait();
                    System.out.println("马上出lambda的synchronized了");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }, "线程1");

        thread.start();

        while (true) {
            TimeUnit.SECONDS.sleep(4);
            System.out.println("线程1的状态:"+thread.getState());
        }
    }
}
